package com.example.smartcs.controller;

import com.example.smartcs.model.ChatMessage;
import com.example.smartcs.service.SessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/sessions")
@RequiredArgsConstructor
public class SessionController {

    private final SessionService sessionService;

    /**
     * 获取用户的所有会话ID列表
     */
    @GetMapping
    public ResponseEntity<List<String>> getAllSessions() {
        return ResponseEntity.ok(sessionService.getAllSessionIds());
    }
    
    /**
     * 获取特定会话的所有消息
     */
    @GetMapping("/{sessionId}")
    public ResponseEntity<List<ChatMessage>> getSessionMessages(@PathVariable String sessionId) {
        return ResponseEntity.ok(sessionService.getSessionMessages(sessionId));
    }
    
    /**
     * 创建新会话
     */
    @PostMapping
    public ResponseEntity<Map<String, String>> createSession() {
        String sessionId = sessionService.createNewSession();
        return ResponseEntity.ok(Map.of("sessionId", sessionId));
    }
    
    /**
     * 删除会话
     */
    @DeleteMapping("/{sessionId}")
    public ResponseEntity<Void> deleteSession(@PathVariable String sessionId) {
        sessionService.deleteSession(sessionId);
        return ResponseEntity.ok().build();
    }
    
    /**
     * 清空所有会话
     */
    @DeleteMapping
    public ResponseEntity<Void> clearAllSessions() {
        sessionService.clearAllSessions();
        return ResponseEntity.ok().build();
    }
} 